import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:series_play/comm/comm_constant.dart';
import 'package:series_play/comm/dialog_helper.dart';
import 'package:series_play/comm/event/switch_tab_event.dart';
import 'package:series_play/comm/ext/context_ext.dart';
import 'package:series_play/pages/mine/setting_page.dart';
import 'package:series_play/pages/mine/vip/VipPager.dart';
import 'package:series_play/pages/mine/vip/controller/vip_controller.dart';
import 'package:series_play/pages/mine/widget/mine_cell.dart';
import 'package:series_play/utils/jump_helper.dart';
import 'package:series_play/widget/app_color.dart';
import 'package:series_play/widget/app_image.dart';
import '../../comm/base/base_state.dart';
import 'package:series_play/widget/app_text.dart';

import '../../generated/assets.dart';
import 'language_page.dart';
import 'mine_controller.dart';

class MinePage extends StatefulWidget {
  const MinePage({super.key});

  @override
  State<MinePage> createState() => _MinePageState();
}

class _MinePageState extends BaseControllerState<MinePage, MineController> {
  @override
  bool hideAppbar() => true;

  @override
  Widget buildPage(BuildContext context) {
    final top = Row(
      children: [
        //头像
        Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(35).r,
            border: Border.all(color: Colors.white, width: 1.w),
            image: DecorationImage(
              image: NetworkImage(CommConstant.fuckImgData[2]),
              fit: BoxFit.cover,
            ),
          ),
          width: 70.w,
          height: 70.w,
        ),
        12.horizontalSpace,
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            AppText.title('用户名123123', color: Colors.white),
            6.verticalSpace,
            AppText.title(
              'uid：12123123',
              color: AppColor.white_60,
              fontSize: 12,
            ),
          ],
        ),
        const Spacer(),
        GestureDetector(
          onTap: () {
            JumpHelper.login();
          },
          child: Container(
            height: 36.w,
            padding: const EdgeInsets.symmetric(horizontal: 24).w,
            decoration: BoxDecoration(
              color: const Color(0xFF393D45),
              borderRadius: BorderRadius.circular(6).r,
            ),
            alignment: Alignment.center,
            child: AppText(context.tr.login, color: Colors.white, fontSize: 14),
          ),
        ),
      ],
    );

    final vipCard = Container(
      height: 160.w,
      decoration: BoxDecoration(
        color: const Color(0xFF292B34),
        borderRadius: BorderRadius.circular(20).r,
        image: DecorationImage(
          image: AssetImage(Assets.imagesBgMineVipCard),
          fit: BoxFit.fill,
        ),
      ),
      child: Column(
        children: [
          16.verticalSpace,
          Row(
            children: [
              16.horizontalSpace,
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    width: 80.w,
                    height: 18.w,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(Assets.imagesIcMineVip),
                        fit: BoxFit.fitWidth,
                      ),
                    ),
                  ),
                  AppText(
                    '享受专属权益',
                    color: const Color(0xFFF9E1B7),
                    fontSize: 11,
                  ),
                ],
              ),
              const Spacer(),
              GestureDetector(
                onTap: () {
                  Get.to(() => VipPager());
                },
                behavior: HitTestBehavior.translucent,
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  height: 35.w,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      colors: [
                        const Color(0xFFFFC359),
                        const Color(0xFFF9E0B4),
                        const Color(0xFFFFC45A),
                      ],
                    ),
                    borderRadius: BorderRadius.circular(18).r,
                  ),
                  alignment: Alignment.center,
                  child: AppText(
                    '立即开通',
                    fontSize: 16,
                    color: const Color(0xFF603306),
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              16.horizontalSpace,
            ],
          ),
          16.verticalSpace,
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(2).w,
              child: Container(
                decoration: BoxDecoration(
                  color: const Color(0x1aFFD7E2),
                  borderRadius: BorderRadius.circular(20).r,
                ),
                child: Center(
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Row(
                        children: [
                          Expanded(
                            child: Center(
                              child: AppImage(
                                Assets.imagesIcMineRights1,
                                size: 34,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppImage(
                                Assets.imagesIcMineRights2,
                                size: 34,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppImage(
                                Assets.imagesIcMineRights3,
                                size: 34,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppImage(
                                Assets.imagesIcMineRights4,
                                size: 34,
                              ),
                            ),
                          ),
                        ],
                      ),
                      4.verticalSpace,
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Expanded(
                            child: Center(
                              child: AppText(
                                '免费观看\n所有剧集',
                                color: const Color(0xFFEDDDBC),
                                fontSize: 12,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppText(
                                '1080P\n高清画质',
                                color: const Color(0xFFEDDDBC),
                                fontSize: 12,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppText(
                                '免广告',
                                color: const Color(0xFFEDDDBC),
                                fontSize: 12,
                              ),
                            ),
                          ),
                          Expanded(
                            child: Center(
                              child: AppText(
                                'VIP专属标识',
                                color: const Color(0xFFEDDDBC),
                                fontSize: 12,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );

    // 功能列表
    final card = Container(
      padding: const EdgeInsets.symmetric(vertical: 5).w,
      decoration: BoxDecoration(
        color: const Color(0xFF292B34),
        borderRadius: BorderRadius.circular(10).r,
      ),
      child: Column(
        children: [
          MineCell(
            icon: Assets.imagesIcMineWallet,
            title: context.tr.wallet,
            onTap: () {
              JumpHelper.wallet();
            },
          ),
          MineCell(
            icon: Assets.imagesIcMineGift,
            title: context.tr.perks,
            hint: '可领20金币',
            onTap: () {
              emitEvent(SwitchTabEvent(2));
            },
          ),
          MineCell(
            icon: Assets.imagesIcMinePlayHistory,
            title: context.tr.playHistory,
            onTap: () {},
          ),
          MineCell(
            icon: Assets.imagesIcMineService,
            title: context.tr.serverPeople,
            onTap: () {
              DialogHelper.showConnectServiceDialog(context);
            },
          ),
          MineCell(
            icon: Assets.imagesIcMineTranslation,
            title: context.tr.language,
            onTap: () {
              Get.to(() => LanguagePage());
            },
          ),
          MineCell(
            icon: Assets.imagesIcMineSetting,
            title: context.tr.setting,
            onTap: () {
              Get.to(() => SettingPage());
            },
          ),
        ],
      ),
    );

    return Column(
      children: [
        Expanded(
          child: SingleChildScrollView(
            padding: const EdgeInsets.fromLTRB(16, 0, 16, 16).w,
            child: Column(
              children: [
                SizedBox(height: MediaQuery.of(context).padding.top + 30.w),
                top,
                30.verticalSpace,
                vipCard,
                30.verticalSpace,
                card,
              ],
            ),
          ),
        ),
      ],
    );
  }

  @override
  createController() {
    return MineController();
  }

  @override
  bool safeAreaFormTop() => false;

  @override
  bool safeAreaFormBottom() => false;

  @override
  bool showDefaultBackground() {
    return true;
  }
}
